package com.lz.gmall.config;

import com.lz.gmall.properties.MinioProperties;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//文件上传的时候，minioClient对象没有必要多次创建
//将minioClient对象设置为单例，将minioClient对象加入ioc容器，默认情况下就是单例的
@Configuration
@EnableConfigurationProperties(value = MinioProperties.class)
public class MinioConfig {

    @Autowired
    private MinioProperties minioProperties;

    @Bean
    public MinioClient getMinioClient(){

        return MinioClient.builder()
                .endpoint(minioProperties.getEndpoint()) //连接地址
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
    }

}
